﻿@page "/Account/Login"
@inject NavigationManager NavigationManager
@layout EmptyLayOut

@using Microsoft.Extensions.Logging;
@inject ILogger<Login> logger;
<div class="LoginPage">

    <Form Model="@model"
          Layout="@FormLayout.Vertical"
          class="LoginForm">
        <h3>Signin</h3>
        <FormItem Label="用户名">
            <Input @bind-Value="@context.Username" />
        </FormItem>
        <FormItem Label="密码">
            <InputPassword @bind-Value="@context.Password" />
        </FormItem>
        <FormItem>
            <Checkbox @bind-Value="context.RememberLogin">Remember me</Checkbox>
        </FormItem>
        <FormItem>
            <div class="FromButton">
                <Button Type="@ButtonType.Primary" HtmlType="submit" @onclick="Submit">
                    登陆
                </Button>
                <Button Type="@ButtonType.Primary" Style="background:#fff;border-color:#fff" HtmlType="submit" @onclick="Submit">
                    注册
                </Button>
            </div>
            
        </FormItem>
    </Form>
</div>
<style>
    .LoginPage {
        height: 100%;
        display: flex;
        justify-content: center;
        align-items: center;
        background-image: url('images/欢迎界面2.jpg');
    }

    .LoginForm {
        background-color: #fff;
        padding: 20px;
        width: 350px;
        opacity: 0.7;
        background-image: linear-gradient(#d27a8a, #f89c91);
    }

    .LoginForm h3 {
        text-align: center;
        width: 100%;
        margin-bottom: 20px;
    }
    .LoginForm .FromButton {
        display: flex;
        justify-content: center;
        align-items: center;
    }
    .LoginForm .FromButton button{
        margin-right:20px;
    }
</style>
@code
{

    private LoginModel model = new LoginModel();
    private async Task Submit()
    {
        model.ReturnUrl = Common.ReuseMethod.GetUrlQuery(NavigationManager.Uri, "ReturnUrl");
        var res = await Http.PostAsJsonAsync("api/Account/Login", model);
        if (res.Success)
        {
            var url = res.Data.ToString();
            Console.WriteLine(url);
            NavigationManager.NavigateTo(url);
            //await JSRuntime.InvokeVoidAsync("login");
        }
    }
}
